package org.boot.easyapi.server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SuppressWarnings("SpringComponentScan")
@SpringBootApplication
public class EasyApiServerApplication {
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(EasyApiServerApplication.class);
        ConfigurableApplicationContext context = app.run();
        try {
            Environment environment = context.getBean(Environment.class);
            String path = environment.getProperty("server.servlet.context-path")==null?
                    "":environment.getProperty("server.servlet.context-path");
            String port = environment.getProperty("server.port");
            String appname = environment.getProperty("spring.application.name");
            String ip = InetAddress.getLocalHost().getHostAddress();
            System.out.println(
                    "\n\t" +
                            "----------------------------------------------------------\n\t" +
                            "Application"+"【" +appname +"】" + " is running! Access URLs:\n\t" +
                            "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                            "Swagger: \thttp://localhost:" + port + path + "/doc.html\n\t" +
                            "------------------------------------------------------------");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
